package route

import (
	"wespy-http-go/app/activity/2025/summer_drink_car/service"
	"wespy-http-go/app/activity/2025/summer_drink_car/store"
	"wespy-http-go/app/activity/common/actutil"

	"github.com/gin-gonic/gin"
)

// ChangeName 修改店名
func ChangeName(c *gin.Context) {
	req := new(store.ChangeNameReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.ChangeName(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// OpenDoor 开门营业
func OpenDoor(c *gin.Context) {
	req := new(store.OpenDoorReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.OpenDoor(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// SendFlyer 发送传单
func SendFlyer(c *gin.Context) {
	req := new(store.SendFlyerReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.SendFlyer(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// GetTables 获取桌子信息
func GetTables(c *gin.Context) {
	req := new(actutil.CommonReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.GetTables(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// CheckoutTables 结算桌子
func CheckoutTables(c *gin.Context) {
	req := new(actutil.CommonReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.CheckoutTables(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// CheckoutTip 领取小费和口碑分
func CheckoutTip(c *gin.Context) {
	req := new(store.CheckoutTipReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.CheckoutTip(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// SignIn 签到
func SignIn(c *gin.Context) {
	req := new(store.SignInReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.SignIn(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// GetSignDetails 获取签到详情
func GetSignDetails(c *gin.Context) {
	req := new(store.GetSignDetailsReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.GetSignDetails(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// GetSignPopup 获取签到弹窗
func GetSignPopup(c *gin.Context) {
	req := new(store.GetSignPopupReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.GetSignPopup(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// GetShopDetails 获取店铺详情
func GetShopDetails(c *gin.Context) {
	req := new(store.GetShopDetailsReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.GetShopDetails(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// BuyAdvancedBook 购买高级营业秘籍
func BuyAdvancedBook(c *gin.Context) {
	req := new(actutil.CommonReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	err := service.BuyAdvancedBook(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, gin.H{"msg": "购买高级营业秘籍成功"})
}

// GetRankList 获取排行榜列表
func GetRankList(c *gin.Context) {
	req := new(store.GetRankListReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}
	rsp, err := service.GetRankList(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}
	actutil.SuccessResponse(c, rsp)
}

// TestHourlyRank 测试小时排行榜功能（仅用于测试）
func TestHourlyRank(c *gin.Context) {
	req := new(store.TestHourlyRankReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}

	rsp, err := service.TestHourlyRank(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}

	actutil.SuccessResponse(c, rsp)
}

// TestHourlyCheckout 测试小时排行榜结算
func TestHourlyCheckout(c *gin.Context) {
	req := new(store.TestHourlyCheckoutReq)
	if err := c.ShouldBind(req); err != nil {
		actutil.BadParamsResponse(c, err)
		return
	}

	rsp, err := service.TestHourlyCheckout(c.Copy(), req)
	if err != nil {
		actutil.ServerErrorMsgResponse(c, err, "")
		return
	}

	actutil.SuccessResponse(c, rsp)
}
